package byx.container.annotation.demo.ObserverDemo;

import byx.container.annotation.annotation.Register;
import java.util.List;

@Register
public class Subject {
    private final List<Observer> observers;
    private String data;

    public Subject(List<Observer> observers) {
        this.observers = observers;
        setData("initial");
    }

    public void setData(String data) {
        this.data = data;
        notifyAllObservers();
    }

    private void notifyAllObservers() {
        observers.forEach(o -> o.onUpdate(data));
    }
}
